import axios, { AxiosResponse } from 'axios'
import NProgress from 'nprogress'

//定义 响应对象接口
interface ResponseData<T> {
  code: number
  data: T
  message: string
}
const service = axios.create({
  baseURL: '/api',
  timeout: 0,
})
//进度条
NProgress.configure({ showSpinner: false })

service.interceptors.request.use((config) => {
  NProgress.start()
  return config
})

service.interceptors.response.use(
  (response: AxiosResponse<ResponseData<any>>) => {
    const res = response.data
    NProgress.done()
    return res
  }
)

export default service
